package com.ms.oschina.view;

import java.text.DecimalFormat;

import android.content.Context;
import android.graphics.Typeface;
import android.widget.TextView;

import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.FormattedStringCache;
import com.github.mikephil.charting.highlight.Highlight;
import com.ms.oschina.R;

/**
 * Custom implementation of the MarkerView.
 * 
 * @author Philipp Jahoda
 */
public class RadarMarkerView extends MarkerView {

	private TextView tvContent;
	private FormattedStringCache.PrimFloat mFormattedStringCache = new FormattedStringCache.PrimFloat(
			new DecimalFormat("##0"));

	public RadarMarkerView(Context context, int layoutResource) {
		super(context, layoutResource);

		tvContent = (TextView) findViewById(R.id.tvContent);
		tvContent.setTypeface(Typeface.createFromAsset(context.getAssets(),
				"OpenSans-Light.ttf"));
	}

	// callbacks everytime the MarkerView is redrawn, can be used to update the
	// content (user-interface)
	@Override
	public void refreshContent(Entry e, Highlight highlight) {
		float value = e.getY();
		tvContent
				.setText(mFormattedStringCache.getFormattedValue(value) + " %");
	}

	@Override
	public int getXOffset(float xpos) {
		// this will center the marker-view horizontally
		return -(getWidth() / 2);
	}

	@Override
	public int getYOffset(float ypos) {
		// this will cause the marker-view to be above the selected value
		return -getHeight() - 10;
	}
}
